package com.example.app1;

import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

public class MetaDataActivity extends AppCompatActivity {
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_metadata);
        TextView tv_metaData = findViewById(R.id.tv_metaData);
        //获取应用包管理器
        PackageManager pm = getPackageManager();
        try {
            //从应用包管理器中获取当前Activity的所有信息
            ActivityInfo info = pm.getActivityInfo(getComponentName(), PackageManager.GET_META_DATA);
            //从所有的信息中获取附加的元数据信息，是以bundle的形式存在的
            Bundle bundle = info.metaData;
            String weather = bundle.getString("weather");
            tv_metaData.setText(weather);
        } catch (PackageManager.NameNotFoundException e) {
            throw new RuntimeException(e);
        }
        String game = getString(R.string.game);
        tv_metaData.setText(game);
    }
}
